import { defineConfig } from 'vite'
import postCssPxToRem from "postcss-pxtorem";
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint';
// import eslintPlugin from 'vite-plugin-eslint'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    eslintPlugin({
      fix: true, //修复错误
      include: [
        'src/**/*.vue',
        'src/**/*.ts',
        'src/**/*.js'
      ],
    })
  ],
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 39, // 1rem，根据 设计稿宽度/10 进行设置
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  },
  server: {
    host: '0.0.0.0',
    port: 3000,
    hmr: true,
    watch: {
      usePolling: true,   // 修复HMR热更新失效
    },
    proxy: {
      '/api': {
        target: 'http://43.138.15.137:3000', //实际请求地址
        changeOrigin: true, // 是否改变请求源
        rewrite: (path) => path.replace(/^\/api/, "api") // 路径重写
      },
    }
  },
})
